package com.fcscs.cservice.ws.endpoint;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.cservice.ws.schema.common.InfoDetailView;
import com.fcscs.cservice.ws.schema.common.InfoMasterView;
import com.fcscs.cservice.ws.schema.common.InfoMenuListView;
import com.fcscs.cservice.ws.schema.common.PictureFrameView;
import com.fcscs.cservice.ws.schema.common.PictureView;
import com.fcscs.cservice.ws.schema.infomoduleservice.InfoItemDetailRequest;
import com.fcscs.cservice.ws.schema.infomoduleservice.InfoItemDetailResponse;
import com.fcscs.cservice.ws.schema.infomoduleservice.InfoItemRequest;
import com.fcscs.cservice.ws.schema.infomoduleservice.InfoItemResponse;
import com.fcscs.cservice.ws.schema.infomoduleservice.MasterInfoItemRequest;
import com.fcscs.cservice.ws.schema.infomoduleservice.MasterInfoItemResponse;
import com.fcscs.cservice.ws.schema.infomoduleservice.MasterInfoRequest;
import com.fcscs.cservice.ws.schema.infomoduleservice.MasterInfoResponse;
import com.fcscs.ecms.service.ECMSInfoManager;


@Endpoint
public class InfoModuleServiceEndpoint {
	@Autowired
	ECMSInfoManager ecmsInfoManager;
	@PayloadRoot(localPart = CServiceWSConstants.INFO_MODULE_MASTER_RQ, namespace = CServiceWSConstants.INFO_MODULE_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public MasterInfoResponse infoMasterProccess (@RequestPayload MasterInfoRequest req){
		
		System.out.println("running");
//		MasterInfoResponse  rep = new MasterInfoResponse();
//		InfoMasterView in = new InfoMasterView();
//		List<Long> listInt = new ArrayList<Long>();
//		listInt.add(101l);
//		listInt.add(102l);
////		in.setBranchelList(listInt);
//		
////		in.setBranchelList(list)
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
//		in.setPictureFrameView(pictureFrameView);
//		in.setBranchelList(listInt);
//		in.setId(10l);
//		in.setTitle("asdas");
//		in.setVersion(20l);
//		rep.setInfoMasterView(in);
		MasterInfoResponse rep = new MasterInfoResponse();
		InfoMasterView infoMasterView = ecmsInfoManager.getInfoMasterView(req.getOrgId(), req.getPropId(), req.getLanguageId(),req.getId());
		rep.setInfoMasterView(infoMasterView);
		return rep;
	}
	
	@PayloadRoot(localPart = CServiceWSConstants.INFO_MODULE_MASTER_ITEM_RQ, namespace = CServiceWSConstants.INFO_MODULE_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public MasterInfoItemResponse infoMasterItemProccess (@RequestPayload MasterInfoItemRequest req){
		
//		System.out.println("running");
//		MasterInfoItemResponse  rep = new MasterInfoItemResponse();
//		InfoMasterView in = new InfoMasterView();
//		List<Long> listInt = new ArrayList<Long>();
//		listInt.add(101l);
//		listInt.add(102l);
////		in.setBranchelList(listInt);
//		
////		in.setBranchelList(list)
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
//		in.setPictureFrameView(pictureFrameView);
//		in.setBranchelList(listInt);
//		in.setId(10l);
//		in.setTitle("asdas");
//		in.setVersion(20l);
//		rep.setInfoMasterView(in);
		MasterInfoItemResponse rep  = new MasterInfoItemResponse();
		List<InfoMenuListView> infoMenuListViews = ecmsInfoManager.getMasterInfoMenuListView(req.getOrgId(), req.getPropId(), req.getLanguageId()
																		, req.getBarchelsIdList());
		rep.setInfoMenuListViewList(infoMenuListViews);
		
		return rep;
	}

	@PayloadRoot(localPart = CServiceWSConstants.INFO_MODULE_ITEM_DETAIL, namespace = CServiceWSConstants.INFO_MODULE_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public InfoItemDetailResponse infoMasterItemProccess (@RequestPayload InfoItemDetailRequest req){
	InfoItemDetailResponse infoItemDetailResponse = new InfoItemDetailResponse();
	
	infoItemDetailResponse.setInfoDetailView(ecmsInfoManager.getInfoDetailView(req.getOrgId(), req.getPropId(), req.getLanguageId(), req.getId()));
	return infoItemDetailResponse;
	}
	
	@PayloadRoot(localPart = CServiceWSConstants.INFO_MODULE_ITEM_RQ, namespace = CServiceWSConstants.INFO_MODULE_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public InfoItemResponse infoMasterItemProccess (@RequestPayload InfoItemRequest req){
	InfoItemResponse infoItemResponse = new InfoItemResponse();
	
	infoItemResponse.setInfoMenuListViewList(ecmsInfoManager.getMasterInfoMenuListView(req.getOrgId(),req.getPropId(), req.getLanguageId(),req.getBranchelsIdList()));
	return infoItemResponse;
	}
}
